package org.dromara.system.converter;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import org.dromara.system.domain.*;
import org.dromara.system.domain.bo.kq.KQTradingWaterBo;
import org.dromara.system.domain.bo.ld.LDTradingWaterReqDTO;
import org.dromara.system.domain.bo.lsqdb.LSQDBTradingWaterBo;
import org.dromara.system.domain.bo.mxj.MXJTradingWaterBo;
import org.dromara.system.domain.bo.qbqdb.QBQDBTradingWaterBo;
import org.dromara.system.domain.bo.yhb.GTJHTradingWaterBo;
import org.dromara.system.domain.bo.zzb.ZZBTradingWaterBo;
import org.dromara.system.domain.vo.*;
import org.dromara.system.enums.MachineConstant;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author 王星
 * @date 2024/5/29 下午1:48
 */
@Mapper(componentModel = "spring", imports = {NumberUtil.class, LocalDateTimeUtil.class, Convert.class, StrUtil.class, MachineConstant.class,})
public interface MachineConverters {

    MachineConverters INSTANCE = Mappers.getMapper(MachineConverters.class);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getDealMoney()))")
    @Mapping(target = "sn", source = "sn")
    @Mapping(target = "orderNo", source = "orderCode")
    @Mapping(target = "merchantCode", source = "merchantCode")
    @Mapping(target = "merchantName", source = "merchantName")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getServiceMoney()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(Convert.toBigDecimal(reqDTO.getSettlesAmountMoney()))")
    @Mapping(target = "dealRate", source = "dealRate")
    TradingRecords receiveDealRecordsToReceiveDealRecords(ReceiveDealRecordsReqDTO reqDTO);

    SysUserPurseVo sysUserPurseToVo(SysUserPurse sysUserPurse);

    List<BrandVo> toBrandVoList(List<Brand> list);

    List<ProductsLineVo> toProductsLineVoList(List<ProductsLine> productsLines);

    List<SysUserVo> toSysUserVoList(List<SysUser> sysUsers);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getTxnAmt()))")
    @Mapping(target = "sn", source = "snNo")
    @Mapping(target = "orderNo", source = "ordNo")
    @Mapping(target = "merchantCode", source = "mercId")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getMercFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(NumberUtil.sub(Convert.toBigDecimal(reqDTO.getTxnAmt()),Convert.toBigDecimal(reqDTO.getMercFee())))")
    TradingRecords mXJlRecordsToReceiveDealRecords(MXJTradingWaterBo reqDTO);

    SysUserWithdrawalPolicyVo toSysUserWithdrawalPolicyVo(SysUserWithdrawalPolicy sysUserWithdrawalPolicy);

    SysUserCommonConfigVo toSysUserCommonConfigVo(SysUserCommonConfig sysUserCommonConfig);

    WechatConfigVo wechatConfigToVo(WechatConfig wechatConfig);

    @Mapping(target = "amount", expression = "java(NumberUtil.div(Convert.toBigDecimal(reqDTO.getAmount()),MachineConstant.NUMBER.ONE_HUNDRED))")
    @Mapping(target = "sn", source = "sn")
    @Mapping(target = "orderNo", expression = "java(Convert.toStr(reqDTO.getSerial()))")
    @Mapping(target = "merchantCode", source = "merNo")
    @Mapping(target = "merchantName", source = "merName")
    @Mapping(target = "serviceMoney", expression = "java((NumberUtil.div(Convert.toBigDecimal(reqDTO.getTradeCharges()),MachineConstant.NUMBER.ONE_HUNDRED)))")
    @Mapping(target = "settlesAmountMoney", expression = "java(NumberUtil.div(NumberUtil.sub(reqDTO.getAmount(),reqDTO.getTradeCharges()),MachineConstant.NUMBER.ONE_HUNDRED))")
    TradingRecords lDRecordsToReceiveDealRecords(LDTradingWaterReqDTO reqDTO);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getTradeAmt()))")
    @Mapping(target = "sn", source = "deviceSn")
    @Mapping(target = "orderNo", source = "orderno")
    @Mapping(target = "merchantCode", source = "merchantId")
    @Mapping(target = "merchantName", source = "merchantName")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getTradeFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(NumberUtil.sub(Convert.toBigDecimal(reqDTO.getTradeAmt()),Convert.toBigDecimal(reqDTO.getTradeFee())))")
    TradingRecords lSQDRecordsToReceiveDealRecords(LSQDBTradingWaterBo reqDTO);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getTradeAmt()))")
    @Mapping(target = "sn", source = "deviceSn")
    @Mapping(target = "orderNo", source = "orderno")
    @Mapping(target = "merchantCode", source = "merchantId")
    @Mapping(target = "merchantName", source = "merchantName")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getTradeFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(NumberUtil.sub(Convert.toBigDecimal(reqDTO.getTradeAmt()),Convert.toBigDecimal(reqDTO.getTradeFee())))")
    TradingRecords qBQDRecordsToReceiveDealRecords(QBQDBTradingWaterBo reqDTO);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getTradeAmount()))")
    @Mapping(target = "sn", source = "tusn")
    @Mapping(target = "orderNo", source = "orderNo")
    @Mapping(target = "merchantCode", source = "merchantNo")
    @Mapping(target = "merchantName", source = "merchantName")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getTradeFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(Convert.toBigDecimal(NumberUtil.sub(reqDTO.getTradeAmount(),reqDTO.getTradeFee())))")
    TradingRecords zZBRecordsToReceiveDealRecords(ZZBTradingWaterBo reqDTO);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getAmount()))")
    @Mapping(target = "sn", source = "sn")
    @Mapping(target = "orderNo", source = "orderNo")
    @Mapping(target = "merchantCode", source = "merchantNo")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(Convert.toBigDecimal(NumberUtil.sub(reqDTO.getAmount(),reqDTO.getFee())))")
    TradingRecords kQRecordsToReceiveDealRecords(KQTradingWaterBo reqDTO);

    @Mapping(target = "amount", expression = "java(Convert.toBigDecimal(reqDTO.getTradeAmount()))")
    @Mapping(target = "sn", source = "tusn")
    @Mapping(target = "orderNo", source = "orderNo")
    @Mapping(target = "merchantCode", source = "merchantNo")
    @Mapping(target = "merchantName", source = "merchantName")
    @Mapping(target = "serviceMoney", expression = "java(Convert.toBigDecimal(reqDTO.getTradeFee()))")
    @Mapping(target = "settlesAmountMoney", expression = "java(Convert.toBigDecimal(NumberUtil.sub(reqDTO.getTradeAmount(),reqDTO.getTradeFee())))")
    TradingRecords gTJHRecordsToReceiveDealRecords(GTJHTradingWaterBo reqDTO);
}
